//
//  XiTongSheZhiViewController.m
//  XiangMu
//
//  Created by 康世标 on 15/8/12.
//  Copyright (c) 2015年 康世标. All rights reserved.
//

#import "XiTongSheZhiViewController.h"

@interface XiTongSheZhiViewController ()

@end

@implementation XiTongSheZhiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title=@"系统设置";
    UIButton *fanHuiBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    fanHuiBtn.frame=CGRectMake(20, 20, 10, 20);
     self.tabBarController.tabBar.hidden=YES;
    [fanHuiBtn setBackgroundImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    
    [fanHuiBtn addTarget:self action:@selector(FanHui) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *barFanHui=[[UIBarButtonItem alloc]initWithCustomView:fanHuiBtn];
    self.navigationItem.leftBarButtonItem=barFanHui;
    
    _textArr=[[NSArray alloc]initWithObjects:@"消息提醒设置",@"清除缓存", nil];
    [self.tableView1 registerNib:[UINib nibWithNibName:@"ImagViewTableViewCell" bundle:nil] forCellReuseIdentifier:@"imag"];
    
}
#pragma mark---UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        
        return _textArr.count;
    }
    else{
        return 1;
    }
   
    
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        static NSString *s = @"";
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:s];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:s];
        }
        
        
       cell.textLabel.text = [_textArr objectAtIndex:indexPath.row];
        
       cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
       cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        if (indexPath.row==1) {
            
            CGFloat float1 = [[SDImageCache sharedImageCache] getSize];
            
            cell.detailTextLabel.text =[NSString stringWithFormat:@"%.2fM",float1/1024/1024];
                                        

        }
        return cell;
    }
    else{
        
        ImagViewTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"imag" forIndexPath:indexPath];
        cell.backgroundColor=CL_00cc85;
        [cell.tuiChuDengLuBtn addTarget:self action:@selector(tuiChuDengLuBtn1) forControlEvents:UIControlEventTouchUpInside];
        
        return cell;
    }

    
}
#pragma mark---UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0) {
        
        XiaoXiTiXingSheZhiViewController * x = [[XiaoXiTiXingSheZhiViewController alloc] init];
        [self.navigationController pushViewController:x animated:YES];
    }
    else{
        
       
        [[SDImageCache sharedImageCache] clearDisk];
        
        [[SDImageCache sharedImageCache] clearMemory];
        
        MBProgressHUD * hud =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.mode = MBProgressHUDModeText;
        hud.color = CL_00cc85;
        hud.labelText = @"清除缓存成功";
        
        [hud hide:YES afterDelay:2];
        
        hud.removeFromSuperViewOnHide = YES;
        [tableView reloadData];
    }
   
}
#pragma mark---退出登陆
- (void)tuiChuDengLuBtn1{
    
    UIAlertView * alertView =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"您确定要退出登录吗 " delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
    
    [alertView show];
}
#pragma mark -- UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
   
    
    if (buttonIndex == 0) {
        
        NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
        
        [userDefaults removeObjectForKey:@"msg"];
        [userDefaults removeObjectForKey:@"ID"];
        [userDefaults removeObjectForKey:@"nickname"];
        [userDefaults removeObjectForKey:@"age"];
        [userDefaults removeObjectForKey:@"birthday"];
        [userDefaults removeObjectForKey:@"created"];
        [userDefaults removeObjectForKey:@"headImg"];
        [userDefaults removeObjectForKey:@"phoneNum"];
        [userDefaults removeObjectForKey:@"sex"];
        [userDefaults removeObjectForKey:@"updated"];
        
        
        DengLuViewController * deng = [[DengLuViewController alloc]init];
        deng.home = YES;
        UINavigationController * nav =[[UINavigationController alloc]initWithRootViewController:deng];
        
        [self  presentViewController:nav animated:YES completion:nil];
        
        
        
        
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)FanHui{
     self.tabBarController.tabBar.hidden=NO;
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
